VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "WIN32 demo(CPU/SAM/Contactless-CPU)"
   ClientHeight    =   6900
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6600
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   9
      Charset         =   134
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6900
   ScaleWidth      =   6600
   StartUpPosition =   2  'CenterScreen
   WhatsThisHelp   =   -1  'True
   Begin VB.CommandButton Command5 
      Caption         =   "Clear"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4920
      TabIndex        =   13
      Top             =   6360
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Height          =   1935
      Left            =   360
      MultiLine       =   -1  'True
      TabIndex        =   12
      Top             =   4320
      Width           =   6135
   End
   Begin VB.TextBox Text1 
      Height          =   1215
      Left            =   360
      TabIndex        =   11
      Top             =   2400
      Width           =   6135
   End
   Begin VB.ComboBox Combo2 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      ItemData        =   "sample.frx":0000
      Left            =   4440
      List            =   "sample.frx":0002
      Style           =   2  'Dropdown List
      TabIndex        =   10
      Top             =   1080
      Width           =   1695
   End
   Begin VB.CheckBox Check1 
      Caption         =   "USB"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   360
      TabIndex        =   8
      Top             =   120
      Value           =   1  'Checked
      Width           =   1935
   End
   Begin VB.ComboBox Combo1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      ItemData        =   "sample.frx":0004
      Left            =   4440
      List            =   "sample.frx":0006
      Style           =   2  'Dropdown List
      TabIndex        =   7
      Top             =   600
      Width           =   1695
   End
   Begin VB.CommandButton Command7 
      Caption         =   "Card reset"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   2160
      TabIndex        =   5
      Top             =   1680
      Width           =   1935
   End
   Begin VB.CommandButton Command6 
      Caption         =   "Beep"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   4
      Top             =   1080
      Width           =   1455
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4680
      TabIndex        =   3
      Top             =   1680
      Width           =   1455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Sent command"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   2
      Top             =   3720
      Width           =   2055
   End
   Begin VB.CommandButton Command2 
      Caption         =   "RF Reset"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   1
      Top             =   1680
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Initial"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   0
      Top             =   600
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "Chose card"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2280
      TabIndex        =   9
      Top             =   1080
      Width           =   2055
   End
   Begin VB.Label Label1 
      Caption         =   "Chose device"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2280
      TabIndex        =   6
      Top             =   600
      Width           =   2055
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim snr, tagtype As Long
Dim data32(16) As Byte
Dim databuff32(16) As Byte
Dim alldata As String * 3000
Dim rvalue As Long
Dim wvalue As Long
Dim cardmode As Integer
Dim loadmode As Integer
Dim sector As Integer
Dim displaydata(8) As Byte
Dim address As Integer
Dim cardtype As Integer ' 0:CPU,1:SAM1,2:SAM2,3:SAM3,4:Contactless-CPU

Private Sub Msg(srvstr As String)



Text2.Text = vbCrLf + Text2.Text 'Chr(10) + Chr(13) + Text2.Text
Text2.Text = srvstr + Text2.Text

End Sub



Private Sub Combo1_Click()

Dim index As Integer

'Chose special device

If icdev > 0 Then

index = Combo1.ListIndex
icdev = ihdevs(index)

End If

End Sub

Private Sub Combo2_Click() 'chose current card type

cardtype = Combo2.ListIndex

Select Case cardtype
Case 0
st = fw_setcpu(icdev, 12)
Case 1
'st = fw_setcpu(icdev, &HD)
Case 2
'st = fw_setcpu(icdev, &HE)
Case 3
'st = fw_setcpu(icdev, &HF)

End Select

If st <> 0 Then
  Msg ("setup card error")
  Exit Sub
End If

Msg ("setup card success")

End Sub

Private Sub Command1_Click()

Dim tmphdev As Integer
Dim i As Integer
Dim strdev As String

Combo1.Clear

If Check1.value = 1 Then

'loop to get handle of each reader when case of USB

i = 0

Do
  tmphdev = fw_init(100, 0)
  
  strdev = "Reader"
  
  If tmphdev > 0 Then
  ihdevs(i) = tmphdev
  strdev = strdev + str(i)
  
  Combo1.AddItem strdev
  Combo1.Text = strdev
  
  End If
  
  i = i + 1
  
Loop Until tmphdev < 0 And i < 100



Else

'when case of serial port
tmphdev = fw_init(0, 115200) 'COM1, baut rate 115200

If tmphdev > 0 Then
Combo1.AddItem "Reader 0"
Combo1.Text = "Reader 0"
ihdevs(0) = tmphdev

End If

End If 'If Check1.value = 1 Then

icdev = ihdevs(0)

If icdev > 0 Then
Combo1.ListIndex = 0
End If

  

If icdev < 0 Then
   MsgBox "Call fw_init() function error!"
Else
   MsgBox "Call fw_init() function success!"
End If

End Sub



Private Sub Command2_Click() 'RF reset

st = fw_reset(ByVal icdev, 5) 'reset 50ms
If st <> 0 Then
      Msg ("Call fw_reset() function error")
      Exit Sub
End If
 Msg ("Call fw_reset() function success!")
End Sub

Private Sub Command3_Click() 'sent command

Dim strcmd() As Byte
Dim cmdbuf(3000) As Byte
Dim slen As Integer
Dim str As String
Dim buf2str As String
Dim rlen(2) As Byte
Dim revbuf(3000) As Byte
Dim revhexbuf(5000) As Byte



Select Case cardtype

Case 0 To 3  'CPU和SAM card

Dim intx As Integer

For intx = 0 To 4

  Select Case intx
  Case 0
   str = "00A40000022F02"
  Case 1
   str = "00A4020002ef02"
  Case 2
   str = "002000000412345678"
  Case 3
   str = "00d600003c112233445566778811223344556677881122334455667788112233445566778811223344556677881122334455667788112233445566778811223344"
  Case 4
   str = "00b000003c"
   
  End Select
  
  slen = Len(str)
  
  strcmd = StrConv(str, vbFromUnicode)
  
  st = a_hex(cmdbuf(0), strcmd(0), slen / 2)
  
  st = fw_cpuapdu(icdev, slen / 2, cmdbuf(0), rlen(0), revbuf(0))
  
  If st <> 0 Then
    Msg ("Sent command: " + str + "error")
    Exit Sub
  End If
  DoEvents
  
  Msg ("Sent command: " + str + "success")
  
  hex_a revhexbuf(0), revbuf(0), 2 * rlen(0)
  
  
  buf2str = StrConv(revhexbuf, vbUnicode)
  
  Msg ("Command returned: " + buf2str)
  

Next intx


Case 4   'Contactless-CPU

strcmd = StrConv(Text1.Text, vbFromUnicode)
slen = 0

slen = Len(Text1.Text)

If slen <= 0 Then
  Msg ("Enter Command please!")
  Exit Sub
  
End If

DoEvents



st = a_hex(cmdbuf(0), strcmd(0), slen / 2)

If st <> 0 Then
  Msg ("The command data type error")
  Exit Sub
End If

DoEvents
st = fw_pro_commandlink(icdev, slen / 2, cmdbuf(0), rlen(0), revbuf(0), 9, 60)
If st <> 0 Then
  Msg ("Command error")
  Exit Sub
End If

Msg ("Command success")
hex_a revhexbuf(0), revbuf(0), 2 * rlen(0)
buf2str = StrConv(revhexbuf, vbUnicode)

Msg ("Command returned: " + buf2str)


End Select


End Sub

Private Sub Command4_Click()
End
End Sub



Private Sub Command5_Click()

Text2.Text = ""

End Sub

Private Sub Command6_Click()


st = fw_beep(ByVal icdev, 10)
If st <> 0 Then
      Msg ("Call fw_beep() function error")
      Exit Sub
End If
Msg ("Call fw_beep() function success")
DoEvents

End Sub

Private Sub Command7_Click()  'card reset

Dim rlen(2) As Byte
Dim revbuf(256) As Byte
Dim snr As Long
Select Case cardtype
Case 0 To 3
st = fw_cpureset(icdev, rlen(0), revbuf(0))
Case 4
st = fw_config_card(icdev, &H41)
st = fw_card(icdev, 1, snr)
st = fw_pro_reset(icdev, rlen(0), revbuf(0))

End Select

If st <> 0 Then
  Msg ("Card reset error")
  Exit Sub
End If

Msg ("Card reset success")

End Sub

Private Sub Form_Load()

Erase ihdevs
icdev = -1

Combo2.AddItem "CPU"
Combo2.AddItem "SAM1"
Combo2.AddItem "SAM2"
Combo2.AddItem "SAM3"
Combo2.AddItem "Contactless-CPU"


'Combo2.Text = "CPU"
cardtype = 0



End Sub

Private Sub Form_Unload(Cancel As Integer)
quit
End Sub

